import apiClient from '@/api/client'
import type { ApiResponse } from '@/types/common'
import type { Todo, Category } from '../types'

// 获取 Todo 列表
export const getTodoList = async (categoryId?: string, isFavorite?: boolean): Promise<Todo[]> => {
  const params: Record<string, any> = {}
  if (categoryId) params.categoryId = categoryId
  if (isFavorite !== undefined) params.isFavorite = isFavorite

  const response = await apiClient.get<ApiResponse<Todo[]>>('/todo/list', {
    params: Object.keys(params).length > 0 ? params : undefined
  })
  return response.data.data
}

// 获取分类列表
export const getCategoryList = async (): Promise<Category[]> => {
  const response = await apiClient.get<ApiResponse<Category[]>>('/category/list', {
    params: { type: 'TODO' }
  })
  return response.data.data
}

// 获取 Todo 详情
export const getTodoDetail = async (id: string): Promise<Todo> => {
  const response = await apiClient.get<ApiResponse<Todo>>(`/todo/${id}`)
  return response.data.data
}
